using UnityEngine;
using UnityEngine.UI;

public class MagicPrincessTip : BasePanel
{
    [Header("三个按钮")]
    public Button closeButton;
    public Button saveButton;
    public Button attackButton;

    //数据
    SayData data;

    public override void OnClose()
    {
        base.OnClose();
        GameManager.Instance.canOprate=true;
    }

    public override void OnInit()
    {
        base.OnInit();
        path="UI/OtherTip/MagicPrincessTip";

        GameManager.Instance.canOprate=false;
    }

    public override void OnShow(params object[] par)
    {
        base.OnShow(par);

        data=(SayData)par[0];

        closeButton=item.transform.Find("Close").GetComponent<Button>();
        saveButton=item.transform.Find("Save").GetComponent<Button>();
        attackButton=item.transform.Find("Attack").GetComponent<Button>();

        closeButton.onClick.AddListener(CloseButton);
        saveButton.onClick.AddListener(SaveButton);
        attackButton.onClick.AddListener(AttackButton);
    }
    //关闭
    public void CloseButton()
    {
        Close();

        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1f);
    }
    //攻击
    public void AttackButton()
    {
        GameManager.Instance.canOprate = true;
        //直接执行攻击
        GameManager.Instance.StartBattle(data.playerHurtObj, data.player, data.enemy);

        CloseButton();
    }
    //拯救
    public void SaveButton()
    {
        //检测希望之花数量
        if(GameManager.Instance.wishFlower>1)
        {
            //执行希望之花的减少，以及后续逻辑
            GameManager.Instance.ChangeFlower(-1);
            GameManager.Instance.isSavePro = true;
            //提示可以从0层进入花园
            TipSayManager.Instance.Say("<color=yellow> 0层 </color>发生了某种变化");
            //提示Boss被削弱
            TipSayManager.Instance.Say("<color=red> 某个存在 </color>受到了伤害");
        }
        else
        {
            //希望之花不足
            TipSayManager.Instance.Say("<color=yellow> 希望之花 </color> <color=red> 数量不足 </color>");
        }

        CloseButton();
    }
}
